<?php

namespace app\model;

class Railway extends Base
{

    public function news()
    {
        return $this->hasOne('check_record', 'railway_id', 'id')->order('id','desc');
    }
    public function checkRecord()
    {
        return $this->hasMany('check_record', 'railway_id', 'id')->order('id','desc');
    }

    public function station()
    {
        return $this->hasMany('railway_station', 'railway_id', 'id')->order('sort','asc');
    }
    public function segments()
    {
        return $this->hasMany('railway_station', 'railway_id', 'id')->order('sort','asc');
    }

    public function getStationIdsAttr($value,$data)
    {
        return RailwayStation::where(['railway_id' => $data['id']])->column('station_id');
    }
}
